#include<bits/stdc++.h>
using namespace std;
const int N = 1001;
int a[N][N];
int r;
int dp[N][N];
int main()
{
	cin>>r;
	for(int i = 0;i<r;i++)
	{
		for(int j = 0;j<i+1;j++)
		{
			cin>>a[i][j];
		}
	}
	dp[0][0] = a[0][0];
	for(int i = 1;i<r;i++)
	{
		for(int j = 0;j<i+1;j++)
		{
			if(j==0)
			dp[i][j] = dp[i-1][j]+a[i][j];
			else if(j==i)
			dp[i][j] = dp[i-1][j-1]+a[i][j];
			else
			dp[i][j] = max(dp[i-1][j],dp[i-1][j-1])+a[i][j];
		}
	}
	int MAX = 0;
	for(int i = 0;i<r;i++)
	{
		if(dp[r-1][i]>MAX)
		MAX = dp[r-1][i];
	}
	cout<<MAX;
	return 0;
 } 
